﻿#include "CPoolTaskSynRpt.h"
#include "CLogOper.h"

CPoolTaskSynRpt::CPoolTaskSynRpt(QObject *parent) : QObject(parent), QRunnable()
{
	setAutoDelete(true);//放到线程池之后，工作完自动析构(任务执行完毕,该对象自动销毁)

	m_pAllDataInfo = new CAllPdfRptDataInfo();
}

CPoolTaskSynRpt::~CPoolTaskSynRpt()
{
	if (m_pAllDataInfo != nullptr)
	{
		delete m_pAllDataInfo;
		m_pAllDataInfo = nullptr;
	}
}

//设置数据
void CPoolTaskSynRpt::setData(CAllPdfRptDataInfo &dataInfo, CPdfRptBase *pRptBase, QString sRobSceneGuid)
{
	m_pRptBase = pRptBase;
	m_sRobSceneGuid = sRobSceneGuid;

	if (m_pAllDataInfo == nullptr)
	{
		return;
	}

	//公共数据
	{
		m_pAllDataInfo->pubDataInfo.m_sOutputSynPdfFolder = dataInfo.pubDataInfo.m_sOutputSynPdfFolder;
		m_pAllDataInfo->pubDataInfo.m_sOutputSynPdfUrl = dataInfo.pubDataInfo.m_sOutputSynPdfUrl;

		m_pAllDataInfo->pubDataInfo.m_bSynIncRob = dataInfo.pubDataInfo.m_bSynIncRob;
		m_pAllDataInfo->pubDataInfo.m_bSynIncRec = dataInfo.pubDataInfo.m_bSynIncRec;
		m_pAllDataInfo->pubDataInfo.m_bSynIncTear = dataInfo.pubDataInfo.m_bSynIncTear;
		m_pAllDataInfo->pubDataInfo.m_bSynIncRestAi = dataInfo.pubDataInfo.m_bSynIncRestAi;
		m_pAllDataInfo->pubDataInfo.m_bSynIncSese = dataInfo.pubDataInfo.m_bSynIncSese;
		m_pAllDataInfo->pubDataInfo.m_bSynIncBaCam = dataInfo.pubDataInfo.m_bSynIncBaCam;

		m_pAllDataInfo->pubDataInfo.m_sSynBeltName = dataInfo.pubDataInfo.m_sSynBeltName;
		m_pAllDataInfo->pubDataInfo.m_sSynDate = dataInfo.pubDataInfo.m_sSynDate;
		m_pAllDataInfo->pubDataInfo.m_sSynStartTime = dataInfo.pubDataInfo.m_sSynStartTime;
		m_pAllDataInfo->pubDataInfo.m_sSynEndTime = dataInfo.pubDataInfo.m_sSynEndTime;
	}

	//机器人数据
	{
		m_pAllDataInfo->robDataInfo.m_sClientCompanyName = dataInfo.robDataInfo.m_sClientCompanyName;
		m_pAllDataInfo->robDataInfo.m_sTaskActionId = dataInfo.robDataInfo.m_sTaskActionId;
		m_pAllDataInfo->robDataInfo.m_sOutputPdfFolder = dataInfo.robDataInfo.m_sOutputPdfFolder;
		m_pAllDataInfo->robDataInfo.m_sRobPdfPathUrl = dataInfo.robDataInfo.m_sRobPdfPathUrl;
		m_pAllDataInfo->robDataInfo.m_sRobotName = dataInfo.robDataInfo.m_sRobotName;
		m_pAllDataInfo->robDataInfo.m_sTaskName = dataInfo.robDataInfo.m_sTaskName;
		m_pAllDataInfo->robDataInfo.m_sTaskTime = dataInfo.robDataInfo.m_sTaskTime;
		m_pAllDataInfo->robDataInfo.m_sComment = dataInfo.robDataInfo.m_sComment;
		m_pAllDataInfo->robDataInfo.m_sTaskStartTime = dataInfo.robDataInfo.m_sTaskStartTime;
		m_pAllDataInfo->robDataInfo.m_sTaskEndTime = dataInfo.robDataInfo.m_sTaskEndTime;
		m_pAllDataInfo->robDataInfo.m_sTaskStartElecVal = dataInfo.robDataInfo.m_sTaskStartElecVal;
		m_pAllDataInfo->robDataInfo.m_sTaskEndElecVal = dataInfo.robDataInfo.m_sTaskEndElecVal;
		m_pAllDataInfo->robDataInfo.m_sTaskState = dataInfo.robDataInfo.m_sTaskState;
		m_pAllDataInfo->robDataInfo.m_sPercentOfPass = dataInfo.robDataInfo.m_sPercentOfPass;
		m_pAllDataInfo->robDataInfo.m_sInspPointCount = dataInfo.robDataInfo.m_sInspPointCount;
		m_pAllDataInfo->robDataInfo.m_sInspItemCount = dataInfo.robDataInfo.m_sInspItemCount;
		m_pAllDataInfo->robDataInfo.m_sInspItemNorCnt = dataInfo.robDataInfo.m_sInspItemNorCnt;
		m_pAllDataInfo->robDataInfo.m_sInspItemAbnorCnt = dataInfo.robDataInfo.m_sInspItemAbnorCnt;
		m_pAllDataInfo->robDataInfo.m_nInspItemAbnorCnt = dataInfo.robDataInfo.m_nInspItemAbnorCnt;

		m_pAllDataInfo->robDataInfo.m_vecAbnorBriefList = dataInfo.robDataInfo.m_vecAbnorBriefList;
		m_pAllDataInfo->robDataInfo.m_vecFormInspPointInfo = dataInfo.robDataInfo.m_vecFormInspPointInfo;
		m_pAllDataInfo->robDataInfo.m_VecCotDetInfo = dataInfo.robDataInfo.m_VecCotDetInfo;
	}

	//纠偏数据
	{
		m_pAllDataInfo->rectifyDataInfo.m_sOutputPdfFolder = dataInfo.rectifyDataInfo.m_sOutputPdfFolder;

		m_pAllDataInfo->rectifyDataInfo.m_sBeltName = dataInfo.rectifyDataInfo.m_sBeltName;
		m_pAllDataInfo->rectifyDataInfo.m_sDetTime = dataInfo.rectifyDataInfo.m_sDetTime;
		m_pAllDataInfo->rectifyDataInfo.m_sDetStartTime = dataInfo.rectifyDataInfo.m_sDetStartTime;
		m_pAllDataInfo->rectifyDataInfo.m_sDetEndTime = dataInfo.rectifyDataInfo.m_sDetEndTime;
		m_pAllDataInfo->rectifyDataInfo.m_nAlmCount = dataInfo.rectifyDataInfo.m_nAlmCount;
		m_pAllDataInfo->rectifyDataInfo.m_sComment = dataInfo.rectifyDataInfo.m_sComment;

		m_pAllDataInfo->rectifyDataInfo.m_vecFormRecAlmInfo = dataInfo.rectifyDataInfo.m_vecFormRecAlmInfo;
	}

	//撕裂数据
	{
		m_pAllDataInfo->tearDataInfo.m_sOutputPdfFolder = dataInfo.tearDataInfo.m_sOutputPdfFolder;

		m_pAllDataInfo->tearDataInfo.m_sBeltName = dataInfo.tearDataInfo.m_sBeltName;
		m_pAllDataInfo->tearDataInfo.m_sDetTime = dataInfo.tearDataInfo.m_sDetTime;
		m_pAllDataInfo->tearDataInfo.m_sDetStartTime = dataInfo.tearDataInfo.m_sDetStartTime;
		m_pAllDataInfo->tearDataInfo.m_sDetEndTime = dataInfo.tearDataInfo.m_sDetEndTime;
		m_pAllDataInfo->tearDataInfo.m_nAlmCount = dataInfo.tearDataInfo.m_nAlmCount;
		m_pAllDataInfo->tearDataInfo.m_sComment = dataInfo.tearDataInfo.m_sComment;

		m_pAllDataInfo->tearDataInfo.m_vecFormTearAlmInfo = dataInfo.tearDataInfo.m_vecFormTearAlmInfo;
	}

	//其他AI检测数据
	{
		m_pAllDataInfo->extraAiDataInfo.m_sOutputPdfFolder = dataInfo.extraAiDataInfo.m_sOutputPdfFolder;

		m_pAllDataInfo->extraAiDataInfo.m_sBeltName = dataInfo.extraAiDataInfo.m_sBeltName;
		m_pAllDataInfo->extraAiDataInfo.m_sDetTime = dataInfo.extraAiDataInfo.m_sDetTime;
		m_pAllDataInfo->extraAiDataInfo.m_nAlmCount = dataInfo.extraAiDataInfo.m_nAlmCount;
		m_pAllDataInfo->extraAiDataInfo.m_sComment = dataInfo.extraAiDataInfo.m_sComment;
		m_pAllDataInfo->extraAiDataInfo.m_sDetStartTime = dataInfo.extraAiDataInfo.m_sDetStartTime;
		m_pAllDataInfo->extraAiDataInfo.m_sDetEndTime = dataInfo.extraAiDataInfo.m_sDetEndTime;

		m_pAllDataInfo->extraAiDataInfo.m_mapExtraAiInfo = dataInfo.extraAiDataInfo.m_mapExtraAiInfo;
	}
	//声振温检测数据
	{
		m_pAllDataInfo->seseDataInfo.m_sOutputPdfFolder = dataInfo.seseDataInfo.m_sOutputPdfFolder;

		m_pAllDataInfo->seseDataInfo.m_sBeltName = dataInfo.seseDataInfo.m_sBeltName;
		m_pAllDataInfo->seseDataInfo.m_sDetTime = dataInfo.seseDataInfo.m_sDetTime;
		m_pAllDataInfo->seseDataInfo.m_sDetStartTime = dataInfo.seseDataInfo.m_sDetStartTime;
		m_pAllDataInfo->seseDataInfo.m_sDetEndTime = dataInfo.seseDataInfo.m_sDetEndTime;
		m_pAllDataInfo->seseDataInfo.m_nAlmCount = dataInfo.seseDataInfo.m_nAlmCount;
		m_pAllDataInfo->seseDataInfo.m_sComment = dataInfo.seseDataInfo.m_sComment;

		m_pAllDataInfo->seseDataInfo.m_vecFormSeSeAlmInfo = dataInfo.seseDataInfo.m_vecFormSeSeAlmInfo;
	}
	//球机检测数据
	{
		m_pAllDataInfo->bacamDataInfo.m_sOutputPdfFolder = dataInfo.bacamDataInfo.m_sOutputPdfFolder;

		m_pAllDataInfo->bacamDataInfo.m_sBeltName = dataInfo.bacamDataInfo.m_sBeltName;
		m_pAllDataInfo->bacamDataInfo.m_sDetTime = dataInfo.bacamDataInfo.m_sDetTime;
		m_pAllDataInfo->bacamDataInfo.m_sDetStartTime = dataInfo.bacamDataInfo.m_sDetStartTime;
		m_pAllDataInfo->bacamDataInfo.m_sDetEndTime = dataInfo.bacamDataInfo.m_sDetEndTime;
		m_pAllDataInfo->bacamDataInfo.m_nAlmCount = dataInfo.bacamDataInfo.m_nAlmCount;
		m_pAllDataInfo->bacamDataInfo.m_sComment = dataInfo.bacamDataInfo.m_sComment;

		m_pAllDataInfo->bacamDataInfo.m_vecFormBaCamAlmInfo = dataInfo.bacamDataInfo.m_vecFormBaCamAlmInfo;
	}
}

void CPoolTaskSynRpt::run()
{
	if (m_pAllDataInfo == nullptr || m_pRptBase == nullptr)
	{
		return;
	}

	{
		SExecLog exLog;
		exLog.m_nAlarmLevel = enWorkInfo;
		exLog.m_sDescriptionl = A2T("开始输出机器人[%1]的综合报告").arg(m_pAllDataInfo->robDataInfo.m_sRobotName);
		exLog.m_sDevName = m_pAllDataInfo->robDataInfo.m_sRobotName;
		exLog.m_sFuncName = A2T("报表");
		CLogOper::instance().addMsg(exLog);
	}

	//输出
	QString sErrMsg = "";
	m_pRptBase->optSynthPdfRptInfo(*m_pAllDataInfo, sErrMsg);//综合报表输出

	//更新综合报表路径信息
	//CSqlOperRob::instance().updateSynPdfUrl(m_pAllDataInfo->robDataInfo.m_sTaskActionId, m_pAllDataInfo->pubDataInfo.m_sOutputSynPdfUrl, m_pAllDataInfo->pubDataInfo.m_sOutputSynPdfFolder);//更新综合报表PDF URL和本地路径

	{
		SExecLog exLog;
		exLog.m_nAlarmLevel = enWorkInfo;
		exLog.m_sDescriptionl = A2T("输出完毕机器人[%1]的综合报告").arg(m_pAllDataInfo->robDataInfo.m_sRobotName);
		exLog.m_sDevName = m_pAllDataInfo->robDataInfo.m_sRobotName;
		exLog.m_sFuncName = A2T("报表");
		CLogOper::instance().addMsg(exLog);
	}
}
